Skip to content

allow reading uid from ContainerUser to set the Tar entry uid #49770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

baronfel
Copy link
Member

Fixes dotnet/sdk-container-builds#639

We read ContainerUser and, if it is an int or the well-known user name root, apply that value as the Uid on the TarEntries that we create.

One thing that Docker does better here is allowing Groups, as well as user and group values that aren't integers (presumably there's some kind of lookup that happens?).

@github-actions github-actions bot added the Area-Containers Related to dotnet SDK containers functionality label Jul 14, 2025
@baronfel baronfel marked this pull request as ready for review July 17, 2025 23:07
@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 23:07
@baronfel baronfel requested a review from a team as a code owner July 17, 2025 23:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables reading the ContainerUser property to set the UID on tar entries when creating container layers. The implementation supports both numeric user IDs and the special "root" user name, applying the appropriate UID (0 for root) to all files and directories in the container layer.

  • Added TryParseUserId method to parse container user strings into numeric UIDs
  • Modified Layer.FromDirectory to accept and apply user ID to tar entries
  • Updated both containerization entry points to use the parsed user ID

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
ContainerBuilder.cs Added TryParseUserId method and updated containerization to use parsed user ID
CreateNewImage.cs Updated to parse and pass user ID to layer creation
Layer.cs Modified to accept user ID parameter and apply it to tar entries
LayerEndToEndTests.cs Added test to verify user ID is correctly applied to tar entries

Comment on lines +160 to 164
var fileStream = File.OpenRead(file.FullName);
entry = new(TarEntryType.RegularFile, containerPath, entryAttributes)
{
Mode = mode,
DataStream = fileStream
DataStream = fileStream,
};
Copy link
Preview

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The using statement was removed from the FileStream, but the manual disposal at line 182 only happens for entries with DataStream. This creates a resource leak if an exception occurs between opening the stream and writing the entry.

Copilot uses AI. Check for mistakes.

using TransientTestFolder folder = new();

string testFilePath = Path.Join(folder.Path, "TestFile.txt");
string testString = $"Test content for {nameof(SingleFileInFolder)}";
Copy link
Preview

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nameof reference is incorrect - it should be {nameof(UserIdIsAppliedToFiles)} since that's the current test method name, not SingleFileInFolder.

Suggested change
string testString = $"Test content for {nameof(SingleFileInFolder)}";
string testString = $"Test content for {nameof(UserIdIsAppliedToFiles)}";

Copilot uses AI. Check for mistakes.

@baronfel baronfel force-pushed the containers-flow-userid branch from c6f140e to 00034f2 Compare July 17, 2025 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Containers Related to dotnet SDK containers functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ContainerUser and temporary directories and files
1 participant